<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition template="_patrimonio.xhtml">
	<ui:define name="corpo"><br />

		<div id="conteudo">

			<h:form id="form">
			

				<h2>
					<h:outputText value="CADASTRAR PATRIMÔNIO"
						rendered="#{empty patrimonioBean.patrimonio.id}" />
					<h:outputText value="EDITAR PATRIMÔNIO"
						rendered="#{not empty patrimonioBean.patrimonio.id}" />
				</h2>
				<hr /><br />

				<p:messages id="msg" />
				
				<p:fieldset legend="Dados do Patrimônio">
				
				<h:panelGrid columns="4">	
				
				<h:outputLabel value="Item: " for="item" />
					<h:selectOneMenu value="#{patrimonioBean.patrimonio.item}" converter="genericConverter" required="true" requiredMessage="Escolha o Item">
						<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" />
						<f:selectItems value="#{itemBean.itens}" var="item" itemLabel="#{item.produto.tipo}" itemValue="#{item}" />
				</h:selectOneMenu>		
					
				<h:outputLabel value="Setor: " for="setor" />
					<h:selectOneMenu value="#{patrimonioBean.patrimonio.setor}" converter="genericConverter" required="true" requiredMessage="Nome do Setor Inválido">
						<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" />
						<f:selectItems value="#{setorBean.setores}" var="setor" itemLabel="#{setor.nome}" itemValue="#{setor}" />
				</h:selectOneMenu>	
									
				<h:outputLabel value="Tombo: " for="tombo" />
				<p:inputText id="tombo" value="#{patrimonioBean.patrimonio.tombo}" required="true" requiredMessage="Tombo não pode ser nulo" maxlength="5" 
					validatorMessage="Preencha Corretamente o Campo Tombo">
					<f:ajax event="change" />
					<f:validateLength minimum="5" maximum="5" for="tombo" />
				</p:inputText>
				
				<h:outputLabel value="Status: " for="status" />
				<h:selectOneMenu id="status" value="#{patrimonioBean.patrimonio.status}">
					<f:selectItem itemLabel="Em Uso" itemValue="Em Uso" />
					<f:selectItem itemLabel="Emprestado" itemValue="Emprestado" />
					<f:selectItem itemLabel="Inservível" itemValue="Inservível" />
				</h:selectOneMenu>
				
				<h:outputLabel value="OBS: " for="obs" />
				<p:inputTextarea id="obs" value="#{patrimonioBean.patrimonio.obs}" style="width: 400px;">
					<f:ajax event="change" />
				</p:inputTextarea><br /><br />
				
				</h:panelGrid>

				<p:commandButton id="grava" value="GRAVAR" action="#{patrimonioBean.grava}" ajax="false" image="ui-icon-disk">
					<f:ajax render="@all" />
				</p:commandButton>
				
				<p:button id="reset" type="reset" value="LIMPAR"/>
								
				</p:fieldset>
				
				</h:form>
				
			<p:dialog header="Itens" widgetVar="dlgItem" model="true"
				width="900">
				<h:form id="form1">

					<p:outputPanel id="itens">

						<p:dataTable id="listItem" value="#{itemBean.itens}"
							paginator="true" rows="8" var="item"
							style="font-size: 11px" emptyMessage="Não Encontrado">


							<f:facet name="header">
								<h:outputText value="ITENS CADASTRADOS" />
							</f:facet>

							<p:column filterBy="#{item.produto.nome}" filterMatchMode="contains"
									headerText="Nome">
									<h:commandLink value="#{item.produto.nome}" id="item">
										<f:setPropertyActionListener
											target="#{patrimonioBean.patrimonio.item}" value="#{item}" />
									</h:commandLink>
								</p:column>

							<p:column sortBy="#{item.nota.numero}"
								filterBy="#{item.nota.numero}" filterMatchMode="contains"
								headerText="Nota Fiscal">
								<h:outputText value="#{item.nota.numero}" />
							</p:column>
							
							<p:column sortBy="#{item.nota.fornecedor.nome}"
								filterBy="#{item.nota.fornecedor.nome}" filterMatchMode="contains"
								headerText="Fornecedor">
								<h:outputText value="#{item.nota.fornecedor.nome}" />
							</p:column>

						</p:dataTable>

					</p:outputPanel>
				</h:form>
			</p:dialog>	
				
			<p:dialog header="Setores" widgetVar="dlgSetor" model="true"
				width="500">
				<h:form id="form2">

					<p:outputPanel id="setores">

						<p:dataTable id="listSetor" value="#{setorBean.setores}"
							paginator="true" rows="8" var="setor"
							style="font-size: 11px" emptyMessage="Não Encontrado">


							<f:facet name="header">
								<h:outputText value="SETORES CADASTRADOS" />
							</f:facet>

							<p:column filterBy="#{setor.nome}" filterMatchMode="contains"
									headerText="Nome">
									<h:commandLink value="#{setor.nome}" id="setor">
										<f:setPropertyActionListener target="#{patrimonioBean.patrimonio.setor}" value="#{setor}" for="setor" />
									</h:commandLink>
								</p:column>

<!-- 							<p:column sortBy="#{setor.bloco.sigla}" -->
<!-- 								filterBy="#{setor.bloco.sigla}" filterMatchMode="contains" -->
<!-- 								headerText="Bloco"> -->
<!-- 								<h:outputText value="#{setor.bloco.sigla}" /> -  -->
<!-- 								<h:commandLink value="#{setor.nome}" id="bloco"> -->
<!-- 										<f:setPropertyActionListener -->
<!-- 											target="#{patrimonioBean.patrimonio.setor}" value="#{setor}" /> -->
<!-- 									</h:commandLink> -->
<!-- 							</p:column> -->

						</p:dataTable>

					</p:outputPanel>
				</h:form>
			</p:dialog>
			
			
		</div>


	</ui:define>
</ui:composition>
</html>